import sys
from PyQt6.QtWidgets import QApplication, QWidget, QMainWindow, QMessageBox

from test1.UI.login import Ui_MainWindow #must PyUIC


class MainWindow(QMainWindow,Ui_MainWindow):#继承QmainWindow,more farther
    def __init__(self, *args, **kwargs):#self is default parameter;you can add other parameters;
        #*args is mean any parameters; *kwargs is mean any dictronary parameters;
        super().__init__()#继承执行父类的构造函数
        #self.setWindowTitle("Hello World") #set window title;be overrides the title
        #self.ui = Ui_MainWindow()
        self.setupUi(self)
        self.login_button.clicked.connect(self.login)
        #括号里是方法名,不是方法结果,所以不带括号

        bg_color = kwargs.get('setbackgroundColor', None)
        if bg_color:
            self.setStyleSheet(f"background-color: {bg_color};")
        self.show()
    def login(self):
        username = self.username_edit.text()
        password = self.password_edit.text()
        print(username,password)
        if username == "admin" and password == "admin":
            print("登录成功")
            QMessageBox.information(self, "提示", "登录成功") #message box
        else:
            print("登录失败")
            QMessageBox.critical(self, "提示", "登录失败") #false message box


if __name__ == "__main__":
    #print(sys.argv) #['D:\\u\\test\\gitee\\pythonqt\\test1\\改造程序\\new_hello2.py'] print sys.argv;default is this file path.
    app=QApplication(sys.argv)#get parameters from command line.
    w=MainWindow(setbackgroundColor="lightblue") #use MainWindow created a window.
    w.setWindowTitle("Login")
    w.show()#显示窗口
    #app.exec()#运行程序

    sys.exit(app.exec()) #app.exec() is first stop,then out process

    #import time #test app end,but process is not stop.
    #for i in range(10):#genarate a dictionary
    #    print(i)
    #    time.sleep(1)
# app=QApplication([])
# window=QWidget(windowTitle="Hello World",)#创建一个窗口
# window.show()#显示窗口
# app.exec()#运行程序
